package user

import (
	"day12_11_homework/internal/models/response"
	"github.com/gin-gonic/gin"
	"net/http"
)

type sendSmsRequest struct {
	Tel    string `json:"tel" binding:"required"`
	Source string `json:"source" binding:"required"`
}

func SendSMS(c *gin.Context) {
	var sendSms sendSmsRequest

	if err := c.ShouldBindJSON(&sendSms); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	smsResponse := response.SendSmsResponse(sendSms.Tel, sendSms.Source)

	if smsResponse != "" {
		c.JSON(500, gin.H{
			"message": smsResponse,
		})
		return
	}

	c.JSON(200, gin.H{
		"message": "发送成功",
	})

}
